package com.jm.springboot21.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jm.springboot21.mapper.ClazzMapper;
import com.jm.springboot21.pojo.Clazz;
import com.jm.springboot21.pojo.Dept;
import com.jm.springboot21.pojo.PageBean;
import com.jm.springboot21.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;
    @Override
    public List<Clazz> findAll() {
        return clazzMapper.findAll();
    }

    @Override
    public Clazz findByName(String name) {
        return clazzMapper.findByName(name);
    }

    @Override
    public void add(Clazz clazz) {
    clazzMapper.add(clazz);
    }

    @Override
    public void deleteById(int id) {
    clazzMapper.deleteById(id);
    }

    @Override
    public void updateById(Clazz clazz) {
    clazzMapper.updateById(clazz);
    }

    @Override
    public PageBean getDeptByPage(Integer page, Integer pageSize) {
        // 计算偏移量
        int offset = (page - 1) * pageSize;

        // 查询分页数据
        List<Clazz> clazzList = clazzMapper.selectByPage(offset, pageSize);

        // 查询总记录数
        long total = clazzMapper.countTotal();

        // 构建返回的分页结果对象
        PageBean pageBean = new PageBean();
        pageBean.setTotal(total);
        pageBean.setRows(clazzList);

        return pageBean;
    }

    @Override
    public Integer count() {
        return clazzMapper.count();
    }
}
